package com.lhj.security.entity;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import lombok.ToString;
import org.hibernate.annotations.DynamicInsert;
import org.hibernate.annotations.DynamicUpdate;

import javax.persistence.*;
import java.util.List;
import java.util.Set;

/**
 * @author linghaijin
 * @date 2020-04-10 16:51
 */
@Entity
@Table(name = "t_role")
@Data
@ToString
@NoArgsConstructor
@AllArgsConstructor
@DynamicInsert
@DynamicUpdate
public class SysRole {

    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    public Long id;

    /**
     * 角色名称
     */
    private String roleName;

    /**
     * 角色编码
     */
    private String roleCode;


    /**
     * 角色拥有的权限
     */
    @ManyToMany(mappedBy = "roles", fetch = FetchType.EAGER)
    private List<SysPermission> permissions;

    /**
     * 懒加载，不会查询role表
     */
    @ManyToMany(mappedBy = "roles", fetch = FetchType.LAZY)
    private List<SysUser> users;

}
